package adapter;

import java.util.ArrayList;

import utils.ProductImage;

import com.example.lastprojectbeautiplus.R;
import com.squareup.picasso.Picasso;

import android.app.Activity;
import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class ProductImageViewPagerAdapter extends PagerAdapter{
	ArrayList<ProductImage> productImageList;
	Activity activity;
	ImageView imgProduct;
	View view;
	public ProductImageViewPagerAdapter(Activity activity, ArrayList<ProductImage> productImageList) {
		// TODO Auto-generated constructor stub
		this.activity = activity;
		this.productImageList = productImageList;
	}
	
	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		// TODO Auto-generated method stub
		LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.product_image_view_pager_item, null);
        DisplayMetrics metrics = view.getResources().getDisplayMetrics();
        int width;
        width = metrics.widthPixels;
        
		imgProduct = (ImageView) view.findViewById(R.id.imgProduct);
		imgProduct.getLayoutParams().width = width;
		//imgProduct.getLayoutParams().height = height/3;
		
        Picasso.with(activity)
        	.load(productImageList.get(position).getImage_path())
        	.placeholder(R.drawable.image_wait)
        	.into(imgProduct);
        
        ((ViewPager) container).addView(view, 0);
		return view;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return productImageList.size();
	}

	@Override
    public void destroyItem(View arg0, int arg1, Object arg2) {
        ((ViewPager) arg0).removeView((View) arg2);
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == ((View) arg1);
    }

    @Override
    public Parcelable saveState() {
        return null;
    }

}
